﻿@using System.Data
@using ZoomLa.Common
@model System.Data.DataTable
@{
}
@section head{
<title>科目管理</title>
<style>#AllID_Chk { display: none; }</style>
}
@section content{
<div id="EGV">
<div id="BreadDiv" class="container-fluid mysite">
    <div class="row">
        <ol id="BreadNav" class="breadcrumb navbar-fixed-top">
            <li><a href='@(CustomerPageAction.customPath2)I/Main.aspx'>工作台</a></li>
            <li><a href='Papers_System_Manage'>教育模块</a></li>
            <li><a href='QuestList'>考试管理</a></li>
            <li>科目管理<a href='AddQuestion_Class'>[添加科目]</a></li>
            @MvcHtmlString.Create(Call.GetHelp(76))
        </ol>
    </div>
</div>
@if (Model == null || Model.Rows.Count < 1)
{
    <div class="divbox" id="nocontent">暂无分类信息</div>
}
else
{
    <div id="gv">
        <table class="table table-striped table-bordered table-hover">
            <tr><td class="td_s">ID</td><td>名称</td><td width="15%">所属科目</td><td width="30%">操作</td></tr>
            @foreach (DataRow dr in Model.Rows)
            {
                <tr data-layer="1" data-id='@dr["C_Id"]' onclick='LoadChilds(this,@dr["C_Id"]);'>
                    <td>@dr["C_Id"]</td>
                    <td><a href='QuestList?qtype=1&qid=@dr["C_Id"]'><span class='@(DataConverter.CLng(dr["ChildCount"]) > 0 ? "fa fa-folder" : "fa fa-file")'></span></a> <a href='AddQuestion_Class?&ID=@dr["C_Id"]'>@dr["C_ClassName"]</a></td>
                    <td>@(string.IsNullOrEmpty(dr["ParentName"].ToString())? "主科目" :dr["ParentName"] )</td>
                    <td>
                        <a href='AddQuestion_Class?ID=@dr["C_Id"]' title="修改"><span class="fa fa-pencil" title="修改"></span></a>
                        <a href='AddQuestion_Class?Pid=@dr["C_ID"]' class="option_style"><i class="fa fa-plus" title="添加"></i>子科目</a>
                        <a href="AddKnowledge?nid=@dr["C_Id"]" class="option_style"><i class="fa fa-plus" title="添加"></i>知识点</a>
                        <a href="KnowledgeManage?nid=@dr["C_Id"]" class="option_style"><i class="fa fa-list-alt" title="列表"></i>知识点列表</a>
                        <a href='QuestList?NodeID=@dr["C_Id"]' class="option_style"><i class="fa fa-navicon" title="内容"></i>试题内容</a>
                        <a href="javascript:;" onclick='mvcpage.del({url:"Question_Class_Del",id:@dr["C_Id"]});' class="option_style" title="删除"><span class="fa fa-trash-o" title="删除"></span>删除</a>
                    </td>
                </tr>
            }
        </table>
    </div>
}
</div>
}
@section script{
<script src="/JS/Controls/ZL_Array.js"></script>
<script>
var Temp = "<tr data-layer='@@layer' data-pid='@@C_Classid' data-id='@@C_id' onclick='LoadChilds(this,@@C_id)'>"
        + "<td>@@C_id</td><td>@@layerhtml<img src='/Images/TreeLineImages/t.gif'><a href='QuestList?type=1&tag=@@C_id'><span class='@@imgicon'></span></a> <a href='AddQuestion_Class?ID=@@C_id'>@@C_ClassName</a></td>"
        + "<td>@@ParentName</td><td><a href='AddQuestion_Class?ID=@@C_id' title='修改'><span class='fa fa-pencil'></span></a>"
        + " <a href='AddQuestion_Class?pid=@@C_id' class='option_style'><i class='fa fa-plus' title='添加'></i>子科目</a>"
        + " <a href='AddKnowledge?nid=@@C_id' class='option_style'><i class='fa fa-plus' title='添加'></i>知识点</a>"
        + " <a href='KnowledgeManage?nid=@@C_id' class='option_style'><i class='fa fa-list-alt' title='列表'></i>知识点列表</a>"
        + " <a href='QuestList?qtype=1&pid=@@C_id' class='option_style'><i class='fa fa-navicon' title='内容'></i>试题内容</a>"
        + " <a href='javascript:;' onclick='mvcpage.del({url:\"Question_Class_Del\",id : @@C_id});' class='option_style' title='删除'><span class='fa fa-trash-o'></span>删除</a></td></tr>"
var layerTemp = "<img src='/Images/TreeLineImages/tree_line4.gif' />";
function LoadChilds(obj, id) {
    $.ajax({
        type: "Post",
        url: "Question_Class_GetChild",
        data: { id: id },
        success: function (data) {
            if (data != "" && data != "[]") {
                data = JSON.parse(data);
                var html = ReplaceTlp(Temp, $(obj).data("layer"), data);
                obj.onclick = "";
                $(obj).after(html);
                BindEvent(obj);
            }
        },
        error: function (data) {
        }
    });
}
function DelCofim(id) {
    if (confirm("是否确定删除!"))
        $.ajax({
            type: "Post",
            url: "Question_Class_Del",
            data: { id: id },
            success: function (data) {
                if (data == "1") {
                    window.location = location;
                }
            },
            error: function (data) {
            }
        });
}
function ReplaceTlp(Temp, layer, data) {
    var layerhtml = ""; var html = "";
    for (var i = 0; i <layer; i++) {
        layerhtml += layerTemp;
    }
    Temp = Temp.replace(/@@layerhtml/g, layerhtml).replace(/@@layer/g, ++layer);
    for (var i = 0; i < data.length; i++) {
        var curtemp = Temp.replace(/@@ParentName/g,data[i].ParentName==""?"主科目":data[i].ParentName).replace(/@@imgicon/g, data[i].ChildCount > 0 ? "fa fa-folder" : "fa fa-file");
        html += JsonHelper.FillData(curtemp, data[i]);
    }
    return html;
}
function BindEvent(obj) {
    $(obj).unbind('click');
    $(obj).find(".fa-folder").attr("class", "fa fa-folder-open");
    $(obj).dblclick(function () {
        var pid = $(this).data("id");
        if ($("#EGV tr[data-pid=" + pid + "]").is(":visible")) {
            HideTr(pid);
            $(this).find(".fa-folder-open").attr("class", "fa fa-folder");
        } else {
            $("#EGV").find("[data-pid=" + $(this).data("id") + "]").show();
            $(this).find(".fa-folder").attr("class", "fa fa-folder-open");
        }
    });
}
function HideTr(pid) {
    if ($("#EGV tr[data-pid=" + pid + "]").length < 1) return;
    $("#EGV tr[data-pid=" + pid + "]").each(function (i, v) {
        HideTr($(v).data("id"));
    });
    $("#EGV tr[data-pid=" + pid + "]").find(".fa-folder-open").attr("class", "fa fa-folder");
    $("#EGV tr[data-pid=" + pid + "]").hide();
}
</script>
}